from fastapi import APIRouter, Depends
from sqlalchemy.ext.asyncio import AsyncSession

from crewplus.apps.account.account import AccountDal
from crewplus.apps.account.schemas.account import AccountRegisterIn
from core.database import db_getter
from utils.response import SuccessResponse
import logging

# 配置日志输出到标准输出
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

app = APIRouter()


@app.post("/register", summary="user register via email", description="user register via email, with correct name, email and strong password. passowrd is at least 8 chars, including number and alphabet")
async def register_user(data: AccountRegisterIn, db: AsyncSession = Depends(db_getter)):
    response = await AccountDal(db).register_create_data(data=data)
    logging.info("response ---- " + str(response))
    return SuccessResponse(response)